package com.zhanghe.study.study_scala.collection

/**
 * @author zh
 * @date 2021/5/10 17:55
 */
object TestWordCount {
  def main(args: Array[String]): Unit = {
    val list = List[String]("flume","hive hadoop","zookeeper kafka","hbase zookeeper hadoop")

    val mapList = list.flatMap(_.split(" "))
    println(mapList)

    val wordList = mapList.map((_,1))

    println(wordList)

    val groupMap = wordList.groupBy(_._1)
    println(groupMap)

    val wordCount = groupMap.map( x => (x._1,x._2.size))
    println(wordCount)

    val res = mapList
      .flatMap(_.split(" ")) // 拆分
      .map((_,1)) // 对偶
      .groupBy(_._1) // 分组
      .map(x => (x._1,x._2.size)) // 统计
    println(res)
  }
}
